<!--
sudo apt-get install tasksel
sudp tasksel install lamp-server
-->
<html><head><title>Prepare DataBase</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
</head><body>
<?php
$server = "online-rusca.net.mysql";
$server="localhost";
if($_GET['rp']==""){
$dbUserPass = "22426008";
$dbName="online_rusca_ne";
$dbUser="online_rusca_ne";
$connection=mysql_connect($server,$dbUser,$dbUserPass);// or die(mysql_error());
if(!$connection) echo "Connection to MySQL server failed!\n";

}
else{
$dbUserPass= $_GET["rp"]; //from index
$dbUser="root";
echo "Installation as root@". $server;
$connection=mysql_connect($server,$dbUser,$dbUserPass);// or die(mysql_error());
if(!$connection) echo "Connection to MySQL server failed!\n";

$dbName="es_db";
$dbUser="es_webuser";
$dbUserPass="aRh22";
mysql_query("CREATE DATABASE $dbName CHARACTER SET utf8 COLLATE utf8_general_ci")or die(mysql_error());
mysql_query("CREATE USER $dbUser@'$server' IDENTIFIED BY \"$dbUserPass\"") or die(mysql_error());
mysql_query("GRANT ALL ON $dbName.* TO $dbUser@localhost") or die(mysql_error());

}



/*CREATE CONNECION FILE FOR WEBUSER*/
$str="<?php \n";
$str.="\$dbName='$dbName';\n";
$str.="\$server='$server';\n";
$str.="\$dbUser='$dbUser';\n";
$str.="\$dbUserPass=\"$dbUserPass\";\n";
$str.="\$connection=mysql_connect(\$server,\$dbUser,\$dbUserPass);";
$str.="if(!\$connection){echo \"Connection to MySQL server failed!\";die();}\n";
$str.="if(!mysql_select_db(\$dbName,\$connection)){echo \"Connection to database failed!\";die();}\n";
$str.="?>\n";
$connFile = "../includes/dbConnection.php";
$f = fopen($connFile, 'w');
fwrite($f, $str);
fclose($f);

if(!mysql_select_db($dbName, $connection)){echo "Connection to database failed! \n";}
/* Creating Tables */
mysql_query("CREATE TABLE presentations (presId INT(255) AUTO_INCREMENT PRIMARY KEY NOT NULL, slideNum INT(255) NOT NULL, presTitle TEXT )") or die(mysql_error());

mysql_query("CREATE TABLE slides (slideID INT(255) AUTO_INCREMENT PRIMARY KEY NOT NULL, presId INT(255) NOT NULL, sectionID INT(255) NOT NULL, pageNumber INT(255) NOT NULL, caption TEXT,layout INT(255) NOT NULL, content TEXT )") or die(mysql_error());

mysql_query("CREATE TABLE sections (sectionID INT(255) AUTO_INCREMENT PRIMARY KEY NOT NULL, title VARCHAR(255) NOT NULL )") or die(mysql_error());

echo "Tables created <br>"; 
echo "<a href='create.php'>create sample presentation</a>"; 
?>
</body></html>

